package com.bblocks.enums;

import com.bblocks.config.SwaggerDisplayEnum;
import com.bblocks.exception.ServiceException;
import lombok.Getter;

@Getter
@SwaggerDisplayEnum(index = "state", name = "name")
public enum OrderUserStateEnum {
	INITED(0, "订单初始"),
	TOPAY(1, "待支付"),
	TOSEND(2, "待发货"),
	TODISTRIBUTION(40, "待配送"),
	DISTRIBUTION(41, "配送中"),
	DISTRIBUTIONED(41, "配送完成"),

	TOTAKEOVER(5, "待收货"),
	OVER(6, "已完成"),
	CANCEL(9, "已取消"),
	;

	//订单状态:0=初始,1=待付款,2=待发货,4=配送中,5=待收货,6=已完成,9=已取消
	private Integer state;
	private String name;

	OrderUserStateEnum(Integer state, String name) {
		this.state = state;
		this.name = name;
	}


	@Override
	public String toString() {
		return String.valueOf(state) + ":" + name;
	}

	private static OrderUserStateEnum[] all =  OrderUserStateEnum.values();
	public static OrderUserStateEnum getName(Integer state) {
		if(state == null)
			return null;
		for (OrderUserStateEnum c : all) {
			if (c.getState().equals(state) ) {
				return c;
			}
		}

		throw new ServiceException("无此状态："+state);
	}
}
